local skel = fk.CreateSkill {
  name = "emocp__tianming",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable {
  ["emocp__tianming"] = "天命", -- 俺不中嘞，萌包也有一个天命
  [":emocp__tianming"] = "锁定技，当你成为【杀】的目标后，你弃置两张牌，然后摸两张牌；然后若场上体力唯一最多的角色不为你，该角色须也如此做。",

  ["$emocp__tianming1"] = "皇汉国祚，千年不息！",
  ["$emocp__tianming2"] = "朕乃大汉皇帝，天命之子！",
}

skel:addEffect(fk.TargetConfirmed, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local doTianming = function (p)
      room:askToDiscard(p, {
        min_num = 2,
        max_num = 2,
        include_equip = true,
        skill_name = skel.name,
        cancelable = false,
      })
      if not p.dead then
        p:drawCards(2, skel.name)
      end
    end
    doTianming(player)
    local tos = table.filter(room.alive_players, function (p)
      return table.every(room.alive_players, function (q)
        return p.hp >= q.hp
      end)
    end)
    if #tos ~= 1 or tos[1] == player then return end
    room:doIndicate(player, tos)
    room:notifySkillInvoked(player, skel.name, "support", tos)
    doTianming(tos[1])
  end,
})

return skel
